﻿module Sustainalytics.EsgRatings.Admin {

    import Common = Sustainalytics.Common;
    import CommonAdmin = Sustainalytics.Common.Admin;

    export class KeyESGIssuesService implements IKeyESGIssuesService {

        private $q: ng.IQService;
        private $http: ng.IHttpService;
        private notificationFactory: Common.INotificationFactory;
        private staticObjectsAdmin: CommonAdmin.IStaticObjects;
        private $upload: any;

        constructor(
            $q: ng.IQService,
            $http: ng.IHttpService,
            notificationFactory: Common.INotificationFactory,
            staticObjectsAdmin: CommonAdmin.IStaticObjects,
            $upload) {

            this.$q = $q;
            this.$http = $http;
            this.notificationFactory = notificationFactory;
            this.staticObjectsAdmin = staticObjectsAdmin;
            this.$upload = $upload;
        }

        public uploadKeyESGIssuesFile(dataFile: ArrayBuffer, fileName: string, contentType: string) {
            return this.$upload.http({
                url: "/esgratingserv/api/v1/esgratings/keyesgissues",
                headers: { "Content-Type": contentType, "Content-Disposition": "attachment; filename=\"" + fileName + "\"" },
                data: dataFile
            });
        }
    }


    var mod = angular.module(esgRatingsAdminModuleName);

    // register service with EsgRatings Angular module
    mod.service('KeyESGIssuesService',
        ['$q', '$http', 'notificationFactory', 'staticObjectsAdmin', '$upload', KeyESGIssuesService]);
}